#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define uint unsigned int

#define YES cout << "YES" << '\n'
#define NO cout << "NO" << '\n'
#define endl '\n'
const int INF = 1e9;
const int MOD = 998244353;
using namespace std;

/*思考

*/

void solve() {
    int n, k;
    cin >> n >> k;
    vector<pair<pair<int, int>, int>> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i].first.first >> a[i].first.second >> a[i].second;
    }
    sort(a.begin(), a.end(),
         [](const pair<pair<int, int>, int>& x, const pair<pair<int, int>, int>& y) {
             return x.first.first < y.first.first;
         });
    for (int i = 1; i <= n; i++) {
        if (k >= a[i].first.first && k <= a[i].first.second && a[i].second > k) {
            k = a[i].second;
        }
    }
    cout << k << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 0;
    cin >> t;
    while (t--) solve();
    return 0;
}
